package au.edu.unsw.infs3634.gamifiedlearning.model;

import android.os.Parcel;
import android.os.Parcelable;

import java.util.List;

public class QuizModel implements Parcelable{
    private int id;
    private String name;
    private List<Question> questionList;

    public QuizModel() {
    }

    protected QuizModel(Parcel in) {
        id = in.readInt();
        name = in.readString();
        questionList = in.createTypedArrayList(Question.CREATOR);
    }

    public static final Creator<QuizModel> CREATOR = new Creator<QuizModel>() {
        @Override
        public QuizModel createFromParcel(Parcel in) {
            return new QuizModel(in);
        }

        @Override
        public QuizModel[] newArray(int size) {
            return new QuizModel[size];
        }
    };

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public List<Question> getQuestionList() {
        return questionList;
    }

    public void setQuestionList(List<Question> questionList) {
        this.questionList = questionList;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(id);
        dest.writeString(name);
        dest.writeTypedList(questionList);
    }

    public static class Question implements Parcelable{
        private String title;
        private String rightTag;
        private List<Option> optionList;

        public Question() {
        }

        protected Question(Parcel in) {
            title = in.readString();
            rightTag = in.readString();
            optionList = in.createTypedArrayList(Option.CREATOR);
        }

        public static final Creator<Question> CREATOR = new Creator<Question>() {
            @Override
            public Question createFromParcel(Parcel in) {
                return new Question(in);
            }

            @Override
            public Question[] newArray(int size) {
                return new Question[size];
            }
        };

        public String getTitle() {
            return title;
        }

        public void setTitle(String title) {
            this.title = title;
        }

        public String getRightTag() {
            return rightTag;
        }

        public void setRightTag(String rightTag) {
            this.rightTag = rightTag;
        }

        public List<Option> getOptionList() {
            return optionList;
        }

        public void setOptionList(List<Option> optionList) {
            this.optionList = optionList;
        }

        @Override
        public int describeContents() {
            return 0;
        }

        @Override
        public void writeToParcel(Parcel dest, int flags) {
            dest.writeString(title);
            dest.writeString(rightTag);
            dest.writeTypedList(optionList);
        }

        public static class Option implements Parcelable {
            private String tag;
            private String value;

            public Option() {
            }

            protected Option(Parcel in) {
                tag = in.readString();
                value = in.readString();
            }

            public static final Creator<Option> CREATOR = new Creator<Option>() {
                @Override
                public Option createFromParcel(Parcel in) {
                    return new Option(in);
                }

                @Override
                public Option[] newArray(int size) {
                    return new Option[size];
                }
            };

            public String getTag() {
                return tag;
            }

            public void setTag(String tag) {
                this.tag = tag;
            }

            public String getValue() {
                return value;
            }

            public void setValue(String value) {
                this.value = value;
            }

            @Override
            public int describeContents() {
                return 0;
            }

            @Override
            public void writeToParcel(Parcel dest, int flags) {
                dest.writeString(tag);
                dest.writeString(value);
            }
        }
    }

}
